package com.wao.cms.service;

import com.wao.cms.domain.Website;
import com.wao.cms.repository.WebsiteRepository;
import com.wao.cms.service.dto.WebsiteDTO;
import com.wao.cms.service.mapper.WebsiteMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * Service Implementation for managing Website.
 */
@Service
@Transactional
public class WebsiteService {

    private final Logger log = LoggerFactory.getLogger(WebsiteService.class);

    private final WebsiteRepository websiteRepository;

    private final WebsiteMapper websiteMapper;

    public WebsiteService(WebsiteRepository websiteRepository, WebsiteMapper websiteMapper) {
        this.websiteRepository = websiteRepository;
        this.websiteMapper = websiteMapper;
    }

    /**
     * Save a website.
     *
     * @param websiteDTO the entity to save
     * @return the persisted entity
     */
    public WebsiteDTO save(WebsiteDTO websiteDTO) {
        log.debug("Request to save Website : {}", websiteDTO);
        Website website = websiteMapper.toEntity(websiteDTO);
        website = websiteRepository.save(website);
        return websiteMapper.toDto(website);
    }

    /**
     *  Get all the websites.
     *
     *  @param pageable the pagination information
     *  @return the list of entities
     */
    @Transactional(readOnly = true)
    public Page<WebsiteDTO> findAll(Pageable pageable) {
        log.debug("Request to get all Websites");
        return websiteRepository.findAll(pageable)
            .map(websiteMapper::toDto);
    }

    /**
     *  Get one website by id.
     *
     *  @param id the id of the entity
     *  @return the entity
     */
    @Transactional(readOnly = true)
    public WebsiteDTO findOne(Long id) {
        log.debug("Request to get Website : {}", id);
        Website website = websiteRepository.findOne(id);
        return websiteMapper.toDto(website);
    }

    /**
     *  Delete the  website by id.
     *
     *  @param id the id of the entity
     */
    public void delete(Long id) {
        log.debug("Request to delete Website : {}", id);
        websiteRepository.delete(id);
    }
}
